home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / DirectShow / BaseClasses / ddmm.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-08  |  3.4 KB  |  127 lines

  1. //------------------------------------------------------------------------------
  2. // File: DDMM.cpp
  3. //
  4. // Desc: DirectShow base classes - implements routines for using DirectDraw
  5. //       on a multimonitor system.
  6. //
  7. // Copyright (c) 1995-2001 Microsoft Corporation.  All rights reserved.
  8. //------------------------------------------------------------------------------
  9.  
  10.  
  11. #include <streams.h>
  12. #include <ddraw.h>
  13. #include "ddmm.h"
  14.  
  15. /*
  16.  * FindDeviceCallback
  17.  */
  18. typedef struct {
  19.     LPSTR   szDevice;
  20.     GUID*   lpGUID;
  21.     GUID    GUID;
  22.     BOOL    fFound;
  23. }   FindDeviceData;
  24.  
  25. BOOL CALLBACK FindDeviceCallback(GUID* lpGUID, LPSTR szName, LPSTR szDevice, LPVOID lParam) {
  26.     FindDeviceData *p = (FindDeviceData*)lParam;
  27.  
  28.     if(lstrcmpiA(p->szDevice, szDevice) == 0) {
  29.         if(lpGUID) {
  30.             p->GUID = *lpGUID;
  31.             p->lpGUID = &p->GUID;
  32.         }
  33.         else {
  34.             p->lpGUID = NULL;
  35.         }
  36.         p->fFound = TRUE;
  37.         return FALSE;
  38.     }
  39.     return TRUE;
  40. }
  41.  
  42.  
  43. BOOL CALLBACK FindDeviceCallbackEx(GUID* lpGUID, LPSTR szName, LPSTR szDevice, LPVOID lParam, HMONITOR hMonitor) {
  44.     FindDeviceData *p = (FindDeviceData*)lParam;
  45.  
  46.     if(lstrcmpiA(p->szDevice, szDevice) == 0) {
  47.         if(lpGUID) {
  48.             p->GUID = *lpGUID;
  49.             p->lpGUID = &p->GUID;
  50.         }
  51.         else {
  52.             p->lpGUID = NULL;
  53.         }
  54.         p->fFound = TRUE;
  55.         return FALSE;
  56.     }
  57.     return TRUE;
  58. }
  59.  
  60.  
  61. /*
  62.  * DirectDrawCreateFromDevice
  63.  *
  64.  * create a DirectDraw object for a particular device
  65.  */
  66. IDirectDraw * DirectDrawCreateFromDevice(LPSTR szDevice, PDRAWCREATE DirectDrawCreateP, PDRAWENUM DirectDrawEnumerateP) {
  67.     IDirectDraw*    pdd = NULL;
  68.     FindDeviceData  find;
  69.  
  70.     if(szDevice == NULL) {
  71.         DirectDrawCreateP(NULL, &pdd, NULL);
  72.         return pdd;
  73.     }
  74.  
  75.     find.szDevice = szDevice;
  76.     find.fFound   = FALSE;
  77.     DirectDrawEnumerateP(FindDeviceCallback, (LPVOID)&find);
  78.  
  79.     if(find.fFound) {
  80.         //
  81.         // In 4bpp mode the following DDraw call causes a message box to be popped
  82.         // up by DDraw (!?!).  It's DDraw's fault, but we don't like it.  So we
  83.         // make sure it doesn't happen.
  84.         //
  85.         UINT ErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS);
  86.         DirectDrawCreateP(find.lpGUID, &pdd, NULL);
  87.         SetErrorMode(ErrorMode);
  88.     }
  89.  
  90.     return pdd;
  91. }
  92.  
  93.  
  94. /*
  95.  * DirectDrawCreateFromDeviceEx
  96.  *
  97.  * create a DirectDraw object for a particular device
  98.  */
  99. IDirectDraw * DirectDrawCreateFromDeviceEx(LPSTR szDevice, PDRAWCREATE DirectDrawCreateP, LPDIRECTDRAWENUMERATEEXA DirectDrawEnumerateExP) {
  100.     IDirectDraw*    pdd = NULL;
  101.     FindDeviceData  find;
  102.  
  103.     if(szDevice == NULL) {
  104.         DirectDrawCreateP(NULL, &pdd, NULL);
  105.         return pdd;
  106.     }
  107.  
  108.     find.szDevice = szDevice;
  109.     find.fFound   = FALSE;
  110.     DirectDrawEnumerateExP(FindDeviceCallbackEx, (LPVOID)&find,
  111.         DDENUM_ATTACHEDSECONDARYDEVICES);
  112.  
  113.     if(find.fFound) {
  114.         //
  115.         // In 4bpp mode the following DDraw call causes a message box to be popped
  116.         // up by DDraw (!?!).  It's DDraw's fault, but we don't like it.  So we
  117.         // make sure it doesn't happen.
  118.         //
  119.         UINT ErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS);
  120.         DirectDrawCreateP(find.lpGUID, &pdd, NULL);
  121.         SetErrorMode(ErrorMode);
  122.     }
  123.  
  124.     return pdd;
  125. }
  126.  
  127.